import fs from 'node:fs';
import { checkPath, joinPath } from '@common/utils/nodejs';
import { log } from '@common/utils';

/**
 * 读取配置文件
 * @returns
 */
export const parseDataFile = async <T>(name: string): Promise<T | null> => {
  const path = joinPath(global.lxOldDataPath, name);
  if (await checkPath(path)) {
    try {
      return JSON.parse((await fs.promises.readFile(path)).toString());
    } catch (err) {
      log.error(err);
    }
  }
  return null;
};
